package com.ctrip.ec.biz.dao.album;
import com.ctrip.ec.biz.entity.album.AlbumImageEntity;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.album.AlbumTagEntity;
import com.ctrip.ec.dal.DbAccess;
import com.ctrip.ec.dal.EntityBase;
import com.ctrip.ec.dal.IdConvert;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class AlbumTagDao extends DaoBase<AlbumTagEntity> {
    public AlbumTagDao() {
        super(AlbumTagEntity.class);
    }
    public AlbumTagDao(DbAccess db) {
        super(AlbumTagEntity.class,db);
    }

    public void deleteByAlbumIds(List<Long> ids) throws SQLException {
        if(ids != null && ids.size()>0) {
            String strIds = IdConvert.join(ids);
            String sql = "delete from " + this.getTableName() + " where album_image_id in (" +
                    "select id from " + EntityBase.getTableName(AlbumImageEntity.class) + " where album_id in (" + strIds + "))";
            this.db.execute(sql);
        }

    }
}
